package top.lt.lt_ssm.controller;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import top.lt.lt_ssm.bean.activity;
import top.lt.lt_ssm.service.ActivityService;
import top.lt.lt_ssm.util.SimpleResult;

@Controller
@RequestMapping("/activity")
public class ActivityController {
	@Resource
	private ActivityService activityService;
	
	@RequestMapping("/upd")
	public String upd(activity stl) {
	int upd = activityService.upd(stl);
	if (upd!=0) {
		return "redirect:list";
	} else
		return "redirect:list";
	}
	@RequestMapping("/byid/{actId}")
	public String GetbyID(@PathVariable("actId") int actId,Model model){
		activity getActivityBy = activityService.GetActivityBy(actId);
		model.addAttribute("bp", getActivityBy);
		return "tj/xg_activity";
	}
	
	@RequestMapping("/add")
	public String add(activity stl) {
	int input = activityService.input(stl);
	System.out.println(input);
		return "redirect:list";
	}
	
	@RequestMapping("/GetAll")
	public @ResponseBody SimpleResult GetAll() {
		List<activity> gma = activityService.GetActivityAll();
		gma.forEach(s->{
			System.out.println(s);
		});
		return new SimpleResult(gma);
	}
	
	@RequestMapping("/Getin1/{in1}")
	public @ResponseBody SimpleResult Getin1(@PathVariable("in1") String bt) throws Exception {
		List<activity> gatin1 = activityService.gatin1(bt);
		return new SimpleResult(gatin1!=null?gatin1:false);
	}
	
	@RequestMapping("/del/{actId}")
	public @ResponseBody SimpleResult del(@PathVariable("actId") int actId){
		int delByid = activityService.DelByid(actId);
		return new SimpleResult(delByid>0?true:false);
	}
	
	@RequestMapping("/list")
	public String activityList() {
		return "activity/activity_list";
	}
	@RequestMapping("/tj_a")
	public String tj_a() {
		return "tj/tj_activity";
	}
	@RequestMapping("/tj_m")
	public String tj_m() {
		return "tj/xg_activity";
	}
	@RequestMapping("/tj_e")
	public String tj_e() {
		return "tj/tj_evaluate";
	}
}
